home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 126-150 / scopedisk138 / basicpreprocessor / bpp.bas < prev    next >
Encoding:
BASIC Source File  |  1995-03-19  |  3.3 KB  |  172 lines

  1. REM Bpp - Basic Pre-Processor
  2. REM © 1990 by Steven D. Kapplin
  3. REM Version 1.0 - 7/7/90
  4. REM
  5. REM Takes input file and builds a list of subroutines and functions,
  6. REM then reads a library file and extracts the required subroutines
  7. REM and functions and appends then to the input file.
  8. REM
  9. REM $OPTION Y+,k50,G-
  10. REM
  11. REM EXTERNAL
  12. REM SUB ParseCommandString
  13. REM FUNCTION testdelim%
  14. REM SUB explodes
  15. REM ENDEXTERNAL
  16. DECLARE FUNCTION testdelim%
  17.  
  18. DIM SHARED words$(20)
  19. DIM FuncNames$(1001)
  20.  
  21. DEFINT TRUE
  22. DEFINT FALSE
  23. DEFINT BufLen
  24.  
  25. CONST BufLen=16384
  26.  
  27. CALL ParseCommandString(COMMAND$,argv%,argc$())
  28.  
  29. IF argv% = 0 OR UCASE$(argc$(1)) = "?" THEN
  30.     CALL HelpMsg
  31.     END
  32. END IF
  33. IF argv% = 1 THEN
  34.     PRINT "No Lib File Specified"
  35.     PRINT
  36.     END
  37. END IF
  38. IF NOT FEXISTS(argc$(1)) THEN
  39.     PRINT "Cannot Find Input File"
  40.     PRINT
  41.     END
  42. END IF
  43. IF NOT FEXISTS(argc$(2)) THEN
  44.     PRINT "Cannot Find Lib File"
  45.     PRINT
  46.     END
  47. END IF
  48.  
  49. POKE SYSTAB+33,0
  50.  
  51. OPEN "i",#1,argc$(1),BufLen
  52.  
  53. NumSubs%=0
  54.  
  55. DO 
  56.     LINE INPUT #1,record$
  57.     CALL explodes(record$," ,",words$(),count%)
  58.     IF UCASE$(words$(2))="EXTERNAL" THEN
  59.         DO
  60.             LINE INPUT #1,record$
  61.             CALL explodes(record$," ,",words$(),num%)
  62.             test$=words$(2)
  63.             IF UCASE$(test$)="ENDEXTERNAL" THEN EXIT DO
  64.             INCR NumSubs%
  65.             FuncNames$(NumSubs%) = words$(3)
  66.         LOOP
  67.     END IF
  68. LOOP UNTIL UCASE$(test$)="ENDEXTERNAL" OR EOF(1)
  69.  
  70. IF NumSubs% = 0 THEN
  71.     PRINT "No Subroutines or Functions Declared"
  72.     PRINT
  73.     CLOSE
  74.     POKE SYSTAB+33,2
  75.     END
  76. END IF
  77.  
  78. CLOSE 1
  79.  
  80. OPEN "i",#2,argc$(2),BufLen
  81.  
  82. IF argv% < 3 THEN
  83.     OPEN "a",#3,argc$(1),BufLen
  84. ELSE
  85.     OPEN "o",#3,argc$(3),BufLen
  86. END IF
  87.  
  88. DO WHILE NOT EOF(2)
  89.     LINE INPUT #2,record$
  90.     CALL explodes(record$," ,",words$(),count%)
  91.     IF UCASE$(words$(1))="REM" THEN
  92.         FOR i%=1 TO NumSubs%
  93.             IF UCASE$(words$(2))=UCASE$(FuncNames$(i%)) THEN
  94.                 DO
  95.                     LINE INPUT #2,record$
  96.                     CALL explodes(record$," ,",words$(),count%)
  97.                     test$=UCASE$(words$(1))+" "+UCASE$(words$(2))
  98.                     PRINT #3,record$
  99.                     IF test$="END SUB" OR test$="END FUNCTION" THEN EXIT DO
  100.                 LOOP
  101.             END IF
  102.         NEXT i%
  103.     END IF
  104. LOOP
  105.  
  106.  
  107. CLOSE
  108. POKE SYSTAB+33,2
  109. END
  110.  
  111. SUB HelpMsg
  112.     PRINT CHR$(27)+"[1m"+"Bpp - Basic Pre-Processor, Ver. 1.0"+CHR$(27)+"[0m"
  113.     PRINT CHR$(27)+"[33m"+"© 1990 by Steven D. Kapplin"+CHR$(27)+"[31m"
  114.     PRINT
  115.     PRINT "Syntax: Bpp PgmFile LibFile [OutFile]"
  116. END SUB
  117.  
  118. SUB ParseCommandString(s$,argv%,argc$(1))
  119.     CALL explodes(s$," ,",words$(),count%)
  120.     argv%=count%
  121.     FOR i%=1 TO argv%
  122.         argc$(i%)=words$(i%)
  123.     NEXT i%
  124. END SUB
  125.  
  126. REM Testdelim%
  127. 'utility routine used by some of these subroutines
  128. FUNCTION Testdelim%(s$,delim$,i%)
  129.       IF (INSTR(delim$,MID$(s$,i%-1,1))=0) AND (INSTR(delim$,MID$(s$,i%,1))>0)
  130.             Testdelim%= 1
  131.       ELSE
  132.             Testdelim%= 0
  133.       END IF
  134. END FUNCTION
  135.  
  136. REM explodes
  137. 'Same as exploden, except that strings are placed in array words$()
  138. SUB explodes(s$,delim$,words$(1),count%)
  139.       l%=LEN(s$)
  140.       IF l%=0 THEN
  141.             EXIT SUB
  142.       END IF
  143.       i%=1
  144.       count%=0
  145.       WHILE (i%<l%) AND (INSTR(delim$,MID$(s$,i%,1))>0)
  146.             INCR i%
  147.       WEND
  148.       ptr1%=i%
  149.       IF (i%=1) THEN
  150.             i%=2
  151.       END IF
  152.       WHILE i%<=l%
  153.             IF Testdelim%(s$,delim$,i%)=1 THEN
  154.               INCR count%
  155.               ptr2%=i%-1
  156.               words$(count%)=MID$(s$,ptr1%,ptr2%-ptr1%+1)
  157.               WHILE (i%<l%) AND (INSTR(delim$,MID$(s$,i%,1))>0)
  158.                     INCR i%
  159.               WEND
  160.               ptr1%=i%
  161.             END IF
  162.             INCR i%
  163.       WEND
  164.       IF ptr1%<l% THEN
  165.             INCR count%
  166.             words$(count%)=MID$(s$,ptr1%)
  167.       END IF
  168. END SUB
  169.  
  170.  
  171.  
  172.